﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;


namespace ZoambieGaem {
    class Weapon
    {
        public Vector2 worldPosition;
        public int weapontype;
        public int clipSize;
        public int clipAmmo;
        public int totalAmmo;

        public int fireRate;
        public int fireRateCounter;

        public int reloadTime;
        public int reloadCounter;


        public Weapon(Master m, int x, int y, int type, int totalAmmo)
	    {
            this.weapontype = type;

            this.reloadTime = Weapons.getReloadTime(this.weapontype);
            this.reloadCounter = this.reloadTime;

            this.fireRate = Weapons.getFireRate(this.weapontype);
            this.fireRateCounter = this.fireRate;

            this.clipSize = Weapons.getClipSize(this.weapontype);
            this.clipAmmo = this.clipSize;
            this.totalAmmo = totalAmmo;

            this.worldPosition = new Vector2(x, y);
	    }



        public void shoot(Master m) 
        {
            if (m.wpn.weapontype == 3)
            {
                shootShotgun(m);
            }
            else
            {
                Projectile p = new Projectile(m, this.weapontype, m.player.angle);
                m.projectileList.AddLast(p);
                this.fireRateCounter = 0;
                this.clipAmmo -= 1;
                this.totalAmmo -= 1;

                if (this.clipAmmo == 0 || this.totalAmmo == 0)
                {
                    this.reloadCounter = 0;
                    this.clipAmmo = this.clipSize;
                }
            }
        }

        public void shootShotgun(Master m)
        {
            float projectileAngle = m.player.angle - 0.5f; //MathHelper.ToRadians(15);

            for(int i=0; i<6; i++)
            {
                Projectile p = new Projectile(m, this.weapontype, projectileAngle);
                m.projectileList.AddLast(p);
                projectileAngle = projectileAngle + 0.2f; //MathHelper.ToRadians(5);
            }
            this.fireRateCounter = 0;
            this.clipAmmo -= 1;
            this.totalAmmo -= 1;

            if (this.clipAmmo == 0 || this.totalAmmo == 0)
            {
                this.reloadCounter = 0;
                this.clipAmmo = this.clipSize;
            }
        }


    }
}

